#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BATCHMSG_LEN 800

int main(int argc, char** argv)
{
	FILE *f;
	f = fopen("batch_data.log", "r");
	char msg[1024];
	char *tmp = NULL;
	int len;
	int offset=0;
	int count=0;

	while(fgets(msg, 1024, f)!=NULL)
	{
		if(strncmp(msg,"A0011",5)==0)
		{
			printf("[%d]: %s\n",strlen(msg),msg);
			len = strlen(msg);
			offset = len-BATCHMSG_LEN;

			tmp = (char*)substring(msg,5,16);
			printf("종목코드: %s\n", tmp);
			free(tmp);

			tmp = (char*)substring(msg,34,73);
			printf("종목명: [%s]\n", rtrim(tmp));
			free(tmp);

			tmp = (char*)substring(msg,143+offset,143+offset);
			printf("관리종목지정여부: %s\n", tmp);
			free(tmp);

			tmp = (char*)substring(msg,146+offset,146+offset);
			printf("거래정지여부: %s\n", tmp);
			free(tmp);

			tmp = (char*)substring(msg,196+offset,204+offset);
			printf("전일종가: %s\n", tmp);
			free(tmp);

			tmp = (char*)substring(msg,235+offset,243+offset);
			printf("상한가: %s\n", tmp);
			free(tmp);

			tmp = (char*)substring(msg,244+offset,252+offset);
			printf("하한가: %s\n", tmp);
			free(tmp);

			tmp = (char*)substring(msg,253+offset,261+offset);
			printf("대용가격: %s\n", tmp);
			free(tmp);

			tmp = (char*)substring(msg,291+offset,305+offset);
			printf("상장주식수: %s\n", tmp);
			free(tmp);

			tmp = (char*)substring(msg,317+offset,317+offset);
			printf("PER부호: %s\n",tmp);
			free(tmp);

			tmp = (char*)substring(msg,318+offset,323+offset);
			printf("PER: %s\n",tmp);
			free(tmp);
			count++;
		}
	}

	printf("count : %d\n", count-1);
	fclose(f);
}
